package DataStreamApi.Transformation算子;

import org.apache.flink.api.common.eventtime.WatermarkStrategy;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.connector.file.src.FileSource;
import org.apache.flink.connector.file.src.reader.TextLineInputFormat;
import org.apache.flink.core.fs.Path;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * 1输入1输出
 */
public class Flink01_MAP {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment executionEnvironment = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(new Configuration());


        FileSource<String> build = FileSource.forRecordStreamFormat(new TextLineInputFormat(), new Path("data/word.txt")).build();

        /**
         * 在 Apache Flink 中，WatermarkStrategy 是用于处理事件时间（Event Time）的核心组件之一。它主要用于定义如何为流中的数据分配时间戳以及生成水印（Watermark），从而支持基于事件时间的窗口操作和时间敏感的计算。
         */

        DataStreamSource<String> stringDataStreamSource = executionEnvironment.fromSource(build, WatermarkStrategy.noWatermarks(), "Flink01_MAP");

        SingleOutputStreamOperator<Integer> map = stringDataStreamSource.map(new MapFunction<String, Integer>() {
            @Override
            public Integer map(String value) throws Exception {
                return value.length();
            }
        });

        map.print();
        executionEnvironment.execute();
    }
}
